<template>
  <el-dialog
    title="編集"
    v-model="dialogVisible"
    @close="dialogFormVisible"
    :close-on-click-modal="false"
    :close-on-press-escape="false"
  >
    <el-form size="small" :model="form" ref="form">
      <el-form-item
        label="銀行名"
        :label-width="formLabelWidth"
        :rules="[{ required: true, message: ' ' }]"
        prop="title"
      >
        <el-input
          v-model="form.title"
          autocomplete="off"
          placeholder="銀行名"
        ></el-input>
      </el-form-item>
      <el-form-item
        label="備考"
        :label-width="formLabelWidth"
        prop="meno"
      >
        <el-input
          v-model="form.meno"
          autocomplete="off"
          placeholder="備考"
        ></el-input>
      </el-form-item>
    </el-form>
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="dialogFormVisible">キャンセル</el-button>
        <el-button type="primary" @click="editMessage" :loading="loading"
          >確定</el-button
        >
      </div>
    </template>
  </el-dialog>
</template>

<script>
import bankApi from "@/api/bank.js";
export default {
  data() {
    return {
      categoryList: [],
      /*左边长度*/
      formLabelWidth: "120px",
      /*是否显示*/
      dialogVisible: false,
      loading: false,
    };
  },
  props: ["open_edit", "form"],
  created() {
    this.dialogVisible = this.open_edit;
  },
  methods: {
    /*修改插件*/
    editMessage() {
      let self = this;
      let params = this.form;
      self.$refs.form.validate((valid) => {
        if (valid) {
          self.loading = true;
          bankApi.edits(params, true)
            .then((data) => {
              self.loading = false;
              ElMessage({
                message: "完了しました",
                type: "success",
              });
              self.dialogFormVisible(true);
            })
            .catch((error) => {
              self.loading = false;
            });
        }
      });
    },
    /*关闭弹窗*/
    dialogFormVisible(e) {
      if (e) {
        this.$emit("closeDialog", {
          type: "success",
          openDialog: false,
        });
      } else {
        this.$emit("closeDialog", {
          type: "error",
          openDialog: false,
        });
      }
    },
  },
};
</script>

<style></style>
